<template>
  <div class="contact-session-item">
    <div class="avatar-box">
      <img :src="avatar || defaultAvatar" class="avatar" />
    </div>
    <div class="info">
      <div class="name-row">
        <span class="name">{{ name }}</span>
        <span v-if="unread > 0" class="unread">{{ unread }}</span>
      </div>
      <div class="message-row">
        <el-text class="msg" truncated>{{ lastMsg || "无未读消息" }}</el-text>
      </div>
      <div class="time-row">
        <span class="time">{{ time }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import defaultAvatar from "@/assets/icons/header-icon.png";
defineProps({
  avatar: String,
  name: String,
  time: String,
  lastMsg: String,
  isVoice: Boolean,
  voiceDuration: [String, Number],
  unread: Number,
});
</script>

<style scoped>
.contact-session-item {
  display: flex;
  align-items: flex-start;
  padding: 10px 10px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
  width: 100%;
}
.contact-session-item:hover,
.contact-session-item.active {
  background: #f5f7fa;
}
.avatar-box {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 10px;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar {
  width: 100%;
  height: 100%;
}
.info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.name-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.name {
  font-weight: 600;
  font-size: 14px;
  color: #000000a7;
}
.message-row {
  width: 100%;
}
.time-row {
  width: 100%;
  text-align: left;
}
.time {
  color: #b0b0b0;
  font-size: 12px;
}
.msg,
.voice {
  color: #888;
  font-size: 13px;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}
.unread {
  background: #8e9fff;
  color: #fff;
  border-radius: 12px;
  font-size: 12px;
  min-width: 18px;
  text-align: center;
  padding: 0 6px;
  margin-left: 8px;
  line-height: 18px;
  height: 18px;
  display: inline-block;
}
</style>
